package top.eleven.sixpence.generaterollbacksql.convertor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.eleven.sixpence.generaterollbacksql.annotation.Convertor;
import top.eleven.sixpence.generaterollbacksql.common.CommonConstant;
import top.eleven.sixpence.generaterollbacksql.common.SQLKey;

/**
 * 建表语句转换——>生成删表语句
 *
 * @author eleven
 */
@Convertor(sqlPrefix = {SQLKey.CREATE_TABLE_C, SQLKey.CREATE_TABLE_L})
public class CreateTableConvertor implements BaseConvertor{
    private static final Logger LOGGER = LoggerFactory.getLogger(CreateTableConvertor.class);
    @Override
    public String convert(String sql) {
        sql = sql.replace(SQLKey.CREATE_TABLE_C, CommonConstant.EMPTY_STRING).replace(SQLKey.CREATE_TABLE_L, CommonConstant.EMPTY_STRING);
        String table = sql.substring(0, sql.indexOf("(")).trim();

        StringBuilder sb = new StringBuilder(SQLKey.DROP_TABLE_C);
        sb.append(CommonConstant.ONE_BLANK)
                .append(table.toUpperCase())
                .append(CommonConstant.SEMICOLON)
                .append(CommonConstant.NEW_LINE);
        return sb.toString();
    }
}
